class_name UnitHealFish
extends UnitBase

@export var item_config: ItemBaseConfig


func pick_new_wander_target():
	# 在矩形范围内随机目标点
	var x_offset = randf_range(-wander_width/2, wander_width/2)
	var y_offset = randf_range(-wander_height/2, wander_height/2)
	target_pos = home_position + Vector2(x_offset, y_offset)
	
	# 下一次切换目标时间
	timer = randf_range(1.0, change_dir_time)
	
	
func play_wander_animation():
	animation_player.play("idle")
	
	
func process_hit():
	if not hit_cooldown_timer.is_stopped(): return
	
	var areas = hit_area.get_overlapping_areas()
	if areas.size() <= 0: return
	
	for area in areas:
		var source = area.source
		if source is Player:
			death(false)
			
			GlobalData.add_item(item_config)
			level.show_pickup_tip(item_config, level.player.head_up.global_position)
			AudioManager.play_sound("sfx_pickup")
	
	hit_cooldown_timer.stop()
	hit_cooldown_timer.start()
